<?php
// +----------------------------------------------------------------------
// | 验证码发送类
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2019 http://www.qbt8.com All rights reserved.
// +----------------------------------------------------------------------
// | Author: 章顺 <http://www.qbt8.com>
// +----------------------------------------------------------------------
// | date: 2019-01-20 17:10
// +----------------------------------------------------------------------
namespace plugins\qbt_huaxin\service;

class SendSmsService{

    /**
     *  验证码发送
     * @param string $code 验证码
     * @param string $mobile 接收验证码手机
     */
    public static function sendSms($code="",$mobile=""){
        //取出账号、密码、模版
        $info = cmf_get_option("huaxin_sms");
        $url = "https://dx.ipyy.net/smsJson.aspx";
        $param = [
            'action'=>'send',
            'userid'=>'',
            'account'=>$info['account'],
            'password'=>$info['password'],
            'mobile'=>$mobile,
            'content'=>str_replace("###",$code,$info['content'])
        ];
        $param = http_build_query($param);
        $content = self::get_content($url,$param);
        $result = json_decode($content,true);

        if($result['successCounts'] == 1){
            return $result;
        }else{
            return false;
        }
    }

    /**
     * 获取内容
     * @param $url 链接地址
     * @param $param 参数
     */
    public static function get_content($url="",$param=""){
        if($param != ""){
            $url = $url."?".$param;
        }
        $curl = curl_init(); // 启动一个CURL会话
        curl_setopt($curl, CURLOPT_URL, $url);
        curl_setopt($curl, CURLOPT_HEADER, 0);
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); // 跳过证书检查
        $tmpInfo = curl_exec($curl);     //返回api的json对象
        //关闭URL请求
        curl_close($curl);
        return $tmpInfo;    //返回json对象
    }

}